Pandas Datareader

NOTE: Not every geographical location works well with pandas datareader, your firewall may also block it!

Functions from pandas_datareader.data and pandas_datareader.wb extract data from various Internet sources into a pandas DataFrame. Currently the following sources are supported:

  • Yahoo! Finance
  • Google Finance
  • Enigma
  • St.Louis FED (FRED)
  • Kenneth French’s data library
  • World Bank
  • OECD
  • Eurostat
  • Thrift Savings Plan
  • Oanda currency historical rate
  • Nasdaq Trader symbol definitions (remote_data.nasdaq_symbols)

It should be noted, that various sources support different kinds of data, so not all sources implement the same methods and the data elements returned might also differ.


In [1]:
import pandas_datareader.data as web

import datetime

start = datetime.datetime(2015, 1, 1)

end = datetime.datetime(2017, 1, 1)

facebook = web.DataReader("FB", 'google', start, end)

In [2]:
facebook.head()


Out[2]:
Open High Low Close Volume
Date
2016-09-19 129.91 129.94 128.26 128.65 14958794
2016-09-20 128.65 129.17 128.03 128.64 11083808
2016-09-21 129.13 130.00 128.39 129.94 14068336
2016-09-22 130.50 130.73 129.56 130.08 15538307
2016-09-23 127.56 128.60 127.30 127.96 28326266

Experimental Options

The Options class allows the download of options data from Google Finance.

The get_options_data method downloads options data for specified expiry date and provides a formatted DataFrame with a hierarchical index, so its easy to get to the specific option you want.

Available expiry dates can be accessed from the expiry_dates property.


In [3]:
from pandas_datareader.data import Options

fb_options = Options('FB', 'google')

In [4]:
data = fb_options.get_options_data(expiry = fb_options.expiry_dates[0])

In [5]:
data.head()


Out[5]:
Last Bid Ask Chg PctChg Vol Open_Int Root Underlying_Price Quote_Time
Strike Expiry Type Symbol
5.0 2018-01-19 call FB180119C00005000 167.65 166.40 166.80 0.0 0.0 NaN 9359.0 FB 171.64 2017-09-17 04:07:09.282985
put FB180119P00005000 0.01 NaN 0.03 0.0 0.0 NaN 3053.0 FB 171.64 2017-09-17 04:07:09.282985
10.0 2018-01-19 call FB180119C00010000 161.16 161.45 161.80 0.0 0.0 NaN 2859.0 FB 171.64 2017-09-17 04:07:09.282985
put FB180119P00010000 0.01 NaN 0.01 0.0 0.0 NaN 2056.0 FB 171.64 2017-09-17 04:07:09.282985
15.0 2018-01-19 call FB180119C00015000 158.00 156.50 156.90 0.0 0.0 NaN 235.0 FB 171.64 2017-09-17 04:07:09.282985

FRED


In [6]:
import pandas_datareader.data as web

import datetime

start = datetime.datetime(2010, 1, 1)

end = datetime.datetime(2017, 1, 1)

gdp = web.DataReader("GDP", "fred", start, end)

In [7]:
gdp.head()


Out[7]:
GDP
DATE
2010-01-01 14681.1
2010-04-01 14888.6
2010-07-01 15057.7
2010-10-01 15230.2
2011-01-01 15238.4